﻿using NovoUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using static NovoSerDesEva.MainForm;
using Sunny.UI;
using NovoSerDes.A2B.MainForm;
using NovoSerDes.Frame;

namespace NovoSerDesEva
{
    internal static class Program
    {
        //public static MainForm mainForm;

        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();

        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole();

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool ifDebug = false;

            StringBuilder retVal = new StringBuilder();
            string configFilePath = Environment.CurrentDirectory + "\\config.ini";
            if (File.Exists(configFilePath))
            {
                int ret = GetPrivateProfileString("Debug", "IfConsole", "", retVal, 10, configFilePath);

                if(ret != 0) 
                {
                    int val = 0;
                    if (int.TryParse(retVal.ToString(), out val))
                    {
                        ifDebug = val == 1 ? true : false;
                    }
                }
            }

            if (ifDebug)
                AllocConsole();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //// 实例化 MainForm 对象
            ////MainForm.GetSerDesCommList();
            //MainForm.GetDataSetList();
            //MainForm mainForm = new MainForm();
            //// 运行 MainForm 实例
            ////Application.Run(new FormMain());
            //UIDispatcher.Initialize(mainForm);
            //Application.Run(mainForm);

            //A2B_MainForm a2b_MainForm = new A2B_MainForm();
            //Application.Run(a2b_MainForm);

            Frame frame = Frame.GetFrame();
            Application.Run(frame);
            
            

            if (ifDebug)
                FreeConsole();
        }
    }
}
